import java.util.List;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        StudentManager studentManager = new StudentManager();
        Scanner scanner = new Scanner(System.in);

        while (true) {
            System.out.println("学生管理系统");
            System.out.println("1. 添加学生信息");
            System.out.println("2. 查询学生信息");
            System.out.println("3. 显示所有学生信息");
            System.out.println("4. 计算平均分数");
            System.out.println("5. 退出");
            System.out.print("请选择一个操作（1-5）：");

            int choice = scanner.nextInt();
            scanner.nextLine(); // 消耗掉之前的换行符

            switch (choice) {
                case 1:
                    System.out.print("输入学生ID：");
                    int id = scanner.nextInt();
                    scanner.nextLine(); // 消耗掉换行符
                    System.out.print("输入学生姓名：");
                    String name = scanner.nextLine();
                    System.out.print("输入学生性别：");
                    String gender = scanner.nextLine();
                    System.out.print("输入学生班级：");
                    String clazz = scanner.nextLine();
                    System.out.print("输入高数成绩：");
                    double mathScore = scanner.nextDouble();
                    System.out.print("输入Java成绩：");
                    double javaScore = scanner.nextDouble();
                    scanner.nextLine(); // 消耗掉换行符

                    Student student = new Student(id, name, gender, clazz, mathScore, javaScore);
                    boolean isAdded = studentManager.addStudent(student);
                    System.out.println("添加学生信息成功: " + isAdded);
                    break;
                case 2:
                    System.out.print("输入学生ID：");
                    int studentId = scanner.nextInt();
                    scanner.nextLine(); // 消耗掉换行符
                    Student queriedStudent = studentManager.queryStudentById(studentId);
                    if (queriedStudent != null) {
                        System.out.println("查询到的学生信息: " + queriedStudent);
                    } else {
                        System.out.println("未找到学生信息");
                    }
                    break;
                case 3:
                    List<Student> allStudents = studentManager.showAllStudents();
                    System.out.println("所有学生信息: " + allStudents);
                    break;
                case 4:
                    System.out.print("输入科目名称（mathScore/javaScore）：");
                    String subject = scanner.nextLine();
                    double averageScore = studentManager.calculateAverageScore(subject);
                    System.out.println(subject + " 的平均分: " + averageScore);
                    break;
                case 5:
                    System.out.println("退出系统");
                    scanner.close();
                    return;
                default:
                    System.out.println("无效的选择，请重新输入！");
            }
        }
    }
}